/*
 * PlayerIllnessEvent.java
 * Team qq 2011
 */
package com.google.code.timetrail.backend;

import java.util.List;
import java.util.Random;

/**
 * This the player illness random event
 * 
 * @author Utkarsh
 * @version 1.1
 */
public class PlayerIllnessEvent extends Event {
	/**
	 * PlayerIllnessEvent's SerialVersion ID, to be changed when the object is
	 * changed
	 **/
	private static final long serialVersionUID = 5030L;

	/**
	 * the instance of the game that is acted upon by the Event
	 */
	private final Control gameControl;

	/**
	 * A List of the players in the party
	 */
	private final List<Person> players;

	/**
	 * the randomly selected person that has a chance to become sick
	 */
	private final Person randomSickPerson;

	/**
	 * Position 3
	 */
	private static final int POSITION_THREE = 3;

	/**
	 * Value 100
	 */
	private static final int VALUE_HUNDRED = 100;

	/**
	 * The event where a player is randomly selected to become Sick. The sucess
	 * of this is random and takes in the person's illness factor, whether or
	 * not they are sick or dead, as well as their immunity skill
	 * 
	 * @param gameControl
	 */
	public PlayerIllnessEvent(Control gameControl) {
		this.gameControl = gameControl;
		final Random rand = new Random();
		players = this.gameControl.getMembers();

		final int removedPersonIndex = rand.nextInt(players.size());
		randomSickPerson = players.get(removedPersonIndex);
		if (!randomSickPerson.isDead()
				&& !randomSickPerson.isSick()
				&& rand.nextDouble() > randomSickPerson.getIllness()
				&& randomSickPerson.getSkills()[POSITION_THREE] > rand
						.nextInt(VALUE_HUNDRED)) {
			super.formatMessage(randomSickPerson
					+ " has gotten Sick in the time stream.");
		} else {
			super.messageText = getDummyText();
		}

	}

	/**
	 * action for event
	 */
	@Override
	public void action() {
		randomSickPerson.sick();
	}
}
